1. Field of the Invention
The present invention relates to a system for optimizing a multiphase type definition in program language processing, a method therefor, and a computer readable recording medium. In particular, the present invention relates to a technique for easily deleting duplication of, e.g., a data type definition for data, a function, or the like of a multiphase type or the like and for avoiding unnecessary data, an unnecessary function, or the like from being instantiated so as to realize generation of an efficient code in a program language processing system for generating an object program from a source program.
2. Background Art
Data handled in a programming language are classified in various data types depending on the available values of the data, the types of operations, and the like. For example, in addition to a basic data type such as an integer type, a real number type, a single-precision type, and a double-precision type, a type using a structure constituted by the same types or different types as a unit is known.
In this manner, many programming languages introduce the concepts of data types of data or functions. Of these types, a multiphase type which can apply an algorithm expressed by making a data type a parameter to data or functions of various types has attracted attention. This multiphase type represents the group of a type. The multiphase type is to define a type which does not depend on an individual type such as an integer type or a real number type by introducing a type variable having a type as a parameter, and makes it possible to realize an efficient programming.
FIG. 1 is a diagram showing a conventional definition for a multiphase type and a usage method thereof, and FIG. 2 is a diagram showing a conventional definition for a instantiated multiphase type.
A definition 101 illustrated in FIG. 1 is a definition for a multiphase type. “T” indicated by 102 denotes declaration of a type variable using a type as a parameter, and “T*” indicated by 103 denotes an actual type variable. When an appropriate type is applied as the type variable by the definition 101 of the multiphase type, an actual definition (instantiated definition) corresponding to each type is generated.
For example, 104 and 105 shown in FIG. 1 requests generation of definitions corresponding to an int type (integer type) and a double type (double-precision type) of multiphase vectors. The instances of definitions indicated by 106 and 107 in FIG. 2 are generated in a language processing system (to be described later). It is called instantiation of data type definition that a definition for a multiphase type is developed and generated by the language processing system to be used as an actual definition.
FIG. 3 is a diagram showing a definition for a multiphase type function in a conventional technique.
A definition indicated by 108 in FIG. 3 defines a multiphase type function. The multiphase type function means a function which does not depend on an individual type.
On the other hand, when an abstract data type is applied to a multiphase type, a function handling data of the abstract data type is particularly called a multiphase type member function. A definition indicated by 109 in FIG. 3 defines a multiphase type member function.
FIG. 4 is a block diagram showing the configuration of a program language processing system in a conventional technique, and FIG. 5 is a concept diagram showing the flow of processes in the program language processing system in a conventional technique.
The conventional program language processing system is comprised by a software driver 201, a preprocessor 203, a language processor 204, and a linker 205 as shown in FIG. 4 to generate an object program from a source program.
The software driver 201 receives a source program group 202 and performs control to sequentially give the source program group to the preprocessor 203, the language processor 204, and linker 205, thereby obtaining an object program as an output file.
More specifically, as shown in FIG. 5, when the source programs 202 are given to the corresponding preprocessors 203, respectively, preprocessing such as translation is executed, and preprocessed programs 207 each having a format which can be interpreted by the language processor 204 of the following stage are obtained. The language processor 204 compiles the preprocessed programs 207, respectively, and outputs relocatable objects 208 to the linker 205 as files. The linker 205 links the input relocatable object files, thereby obtaining an object program 206.
In this program language processing system, when data or the like of a multiphase type is used, the instance of a definition for the multiphase type is generated and developed to realize the routine of the multiphase type.
For example, in a multiphase type shown in FIG. 6, data and inline codes of the multiphase type are requested in units of translation. For this reason, when a multiphase type 310 is used, an instance 311 of a definition for a multiphase type is automatically inserted in units of translation, and a multiphase type name is converted into a unique character string generated according to an appropriate rule as indicated by 312 in FIG. 6, so that a instantiated definition for an int type is realized by a definition for a multiphase type in FIG. 6.
However, in the conventional program language processing system, the following problems are mainly posed when an instance of a definition for multiphase type function or data is generated.
(1) Problem Posed when Definition for Multiphase Type Function
In case of a multiphase type function, when generation of the instance of a definition is requested, it is very difficult that a definition for a function which must generate the instance is detected by the language processing system. More specifically, in case of a standard file configuration having a declaration file (header file) “stack k.h” for the multiphase type, a definition file “stack.cpp” for the multiphase type, a source file using a multiphase type “file.cpp” is captured by an include directive 313 and 314.
However, in the conventional language processing system, since a definition for a multiphase type function cannot be detected, a definition for a multiphase type member function existing in the file “stack.cpp” (shown in FIG. 7B) is not captured by the file “file.cpp”.
Here, a request of instantiation of a definition for a multiphase type is generated by a declaration 315. However, definitions for multiphase type member functions do not exist in units of translation in the file “file.cpp”. For this reason, although the language processing system tries to generate the instance of the definition for the multiphase type member function, since this definition exists in the other file “stack.cpp”, the instance of the definition for the multiphase type member function cannot be generated.
Therefore, in the conventional technique, in order to search for a definition for a multiphase type function, (a) it is requested to place a definition for a multiphase type function in a header file, or (b) the naming rule of a file in which a definition for a multiphase type function is placed is limited.
In the countermeasure against the problem (a), as illustrated in FIG. 8A, not only the declaration of the multiphase type function, but also all definitions indicated by 316 are requested to be described in the header file “stack.h”. Therefore, it is requested in 318 to instantiate a multiphase type function existing in a source file “file.cpp” (shown in FIG. 8B), if the header file is included as indicated by 317, the language processing system can detect definitions for the multiphase type functions in units of translation. However, in case of (a), since re-compiling must be required to change a definition for a multiphase type function, the file configuration has low flexibility.
In the countermeasure in the problem (b), for enabling the language processing system to detect a definition for a multiphase type function, it is requested that the name of a file in which the definition for the multiphase type function must be a name (in many cases, the same name as that of the phase type) determined according to a certain rule.
For example, as shown in FIG. 9A, a definition for a multiphase type member function “Stack” placed in a header file “stack.h” requests a source programmer to place the definition in the same source file name “Stack.cpp” (shown in FIG. 9B) as the multiphase type name “Stack”. In this manner, when it is requested by a declaration 318 to generate the instance of a definition “Stack : : Stack” for a multiphase type function indicated by 319, the language processing system searches a file “Stack.cpp” of a predetermined name for a definition for a member function to make it possible to generate of the instance of the definition for the multiphase type function. However, in case of the problem (b), a plurality of definitions for a multiphase type cannot be described in a header file, files of limited names the number of which is equal to the number of multiphase type must be formed, the source programmer is requested to perform an unnecessary job.
(2) Problem Posed when Instance of Definition for Unnecessary Multiphase Type Member Function
In case of a multiphase type member function, generation of the instance of a member function which is not used increases a compile time, and excessively uses a memory region. More specifically, in case of a definition for a multiphase type illustrated in FIG. 10, when the number of multiphase type member functions indicated by 321 is 100, and the number of actually used multiphase type member functions is only one, it is apparently understood that generation of the instances of the definitions for the 99 remaining multiphase type member functions is not efficient.
Therefore, a conventional technique copes with the problem as follows. That is, the instances of the definitions for all the multiphase type member functions are generated regardless of efficiency, or generation of the instances of the definitions for the multiphase type member functions is delayed until all used multiphase type member functions are proved. The instances of the member functions are inefficiently generated.
(3) Problem Posed when Instance of Definition for Multiphase Type Function is Generated in Plurality of Relocatable Object Files
A definition for a multiphase type function is requested to generate an instance each time the multiphase type function is used. Therefore, the instance of a definition for a multiphase type function is generated every generation request, thereby a plurality of equal definitions exist.
With respect to this, as illustrated in FIG. 11, when the instances of a plurality of definitions 322 and 323 for multiphase type functions are generated, the language processing system has a flag variable representing whether the definitions for the multiphase type functions are instantiated or not to make it possible to avoid a duplicate definition from being generated.
However, when the instances of definitions for multiphase type functions indicated by 324 in another unit of translation (shown in FIG. 11C), the conventional language processing system cannot decide whether the definitions for the specified multiphase type functions have been already generated in another unit of translation or not.
For this reason, the conventional technique uses a method in which a source programmer manually suppresses duplicate generation of the instance of a definition for a multiphase type function by using a special preprocessing directive or a method for deleting definitions for multiphase type functions whose links are duplicate in link processing are used. However, the former requests a source programmer to perform unnecessary limitation, and the latter requires a very long time for the decision process.